// Licensed to Elasticsearch B.V under one or more agreements.
// Elasticsearch B.V licenses this file to you under the Apache 2.0 License.
// See the LICENSE file in the project root for more information.
//
// ███╗   ██╗ ██████╗ ████████╗██╗ ██████╗███████╗
// ████╗  ██║██╔═══██╗╚══██╔══╝██║██╔════╝██╔════╝
// ██╔██╗ ██║██║   ██║   ██║   ██║██║     █████╗
// ██║╚██╗██║██║   ██║   ██║   ██║██║     ██╔══╝
// ██║ ╚████║╚██████╔╝   ██║   ██║╚██████╗███████╗
// ╚═╝  ╚═══╝ ╚═════╝    ╚═╝   ╚═╝ ╚═════╝╚══════╝
// ------------------------------------------------
//
// This file is automatically generated.
// Please do not edit these files manually.
//
// ------------------------------------------------

#nullable restore

using Elastic.Clients.Elasticsearch.Serverless.Fluent;
using Elastic.Clients.Elasticsearch.Serverless.Serialization;
using System;
using System.Collections.Generic;
using System.Linq.Expressions;
using System.Text.Json;
using System.Text.Json.Serialization;

namespace Elastic.Clients.Elasticsearch.Serverless.Aggregations;

public sealed partial class HistogramAggregation
{
	/// <summary>
	/// <para>
	/// Enables extending the bounds of the histogram beyond the data itself.
	/// </para>
	/// </summary>
	[JsonInclude, JsonPropertyName("extended_bounds")]
	public Elastic.Clients.Elasticsearch.Serverless.Aggregations.ExtendedBoundsFloat? ExtendedBounds { get; set; }

	/// <summary>
	/// <para>
	/// The name of the field to aggregate on.
	/// </para>
	/// </summary>
	[JsonInclude, JsonPropertyName("field")]
	public Elastic.Clients.Elasticsearch.Serverless.Field? Field { get; set; }
	[JsonInclude, JsonPropertyName("format")]
	public string? Format { get; set; }

	/// <summary>
	/// <para>
	/// Limits the range of buckets in the histogram.
	/// It is particularly useful in the case of open data ranges that can result in a very large number of buckets.
	/// </para>
	/// </summary>
	[JsonInclude, JsonPropertyName("hard_bounds")]
	public Elastic.Clients.Elasticsearch.Serverless.Aggregations.ExtendedBoundsFloat? HardBounds { get; set; }

	/// <summary>
	/// <para>
	/// The interval for the buckets.
	/// Must be a positive decimal.
	/// </para>
	/// </summary>
	[JsonInclude, JsonPropertyName("interval")]
	public double? Interval { get; set; }

	/// <summary>
	/// <para>
	/// Only returns buckets that have <c>min_doc_count</c> number of documents.
	/// By default, the response will fill gaps in the histogram with empty buckets.
	/// </para>
	/// </summary>
	[JsonInclude, JsonPropertyName("min_doc_count")]
	public int? MinDocCount { get; set; }

	/// <summary>
	/// <para>
	/// The value to apply to documents that do not have a value.
	/// By default, documents without a value are ignored.
	/// </para>
	/// </summary>
	[JsonInclude, JsonPropertyName("missing")]
	public double? Missing { get; set; }

	/// <summary>
	/// <para>
	/// By default, the bucket keys start with 0 and then continue in even spaced steps of <c>interval</c>.
	/// The bucket boundaries can be shifted by using the <c>offset</c> option.
	/// </para>
	/// </summary>
	[JsonInclude, JsonPropertyName("offset")]
	public double? Offset { get; set; }

	/// <summary>
	/// <para>
	/// The sort order of the returned buckets.
	/// By default, the returned buckets are sorted by their key ascending.
	/// </para>
	/// </summary>
	[JsonInclude, JsonPropertyName("order")]
	[SingleOrManyCollectionConverter(typeof(KeyValuePair<Elastic.Clients.Elasticsearch.Serverless.Field, Elastic.Clients.Elasticsearch.Serverless.SortOrder>))]
	public ICollection<KeyValuePair<Elastic.Clients.Elasticsearch.Serverless.Field, Elastic.Clients.Elasticsearch.Serverless.SortOrder>>? Order { get; set; }
	[JsonInclude, JsonPropertyName("script")]
	public Elastic.Clients.Elasticsearch.Serverless.Script? Script { get; set; }

	public static implicit operator Elastic.Clients.Elasticsearch.Serverless.Aggregations.Aggregation(HistogramAggregation histogramAggregation) => Elastic.Clients.Elasticsearch.Serverless.Aggregations.Aggregation.Histogram(histogramAggregation);
	public static implicit operator Elastic.Clients.Elasticsearch.Serverless.TransformManagement.PivotGroupBy(HistogramAggregation histogramAggregation) => Elastic.Clients.Elasticsearch.Serverless.TransformManagement.PivotGroupBy.Histogram(histogramAggregation);
}

public sealed partial class HistogramAggregationDescriptor<TDocument> : SerializableDescriptor<HistogramAggregationDescriptor<TDocument>>
{
	internal HistogramAggregationDescriptor(Action<HistogramAggregationDescriptor<TDocument>> configure) => configure.Invoke(this);

	public HistogramAggregationDescriptor() : base()
	{
	}

	private Elastic.Clients.Elasticsearch.Serverless.Aggregations.ExtendedBoundsFloat? ExtendedBoundsValue { get; set; }
	private Elastic.Clients.Elasticsearch.Serverless.Aggregations.ExtendedBoundsFloatDescriptor ExtendedBoundsDescriptor { get; set; }
	private Action<Elastic.Clients.Elasticsearch.Serverless.Aggregations.ExtendedBoundsFloatDescriptor> ExtendedBoundsDescriptorAction { get; set; }
	private Elastic.Clients.Elasticsearch.Serverless.Field? FieldValue { get; set; }
	private string? FormatValue { get; set; }
	private Elastic.Clients.Elasticsearch.Serverless.Aggregations.ExtendedBoundsFloat? HardBoundsValue { get; set; }
	private Elastic.Clients.Elasticsearch.Serverless.Aggregations.ExtendedBoundsFloatDescriptor HardBoundsDescriptor { get; set; }
	private Action<Elastic.Clients.Elasticsearch.Serverless.Aggregations.ExtendedBoundsFloatDescriptor> HardBoundsDescriptorAction { get; set; }
	private double? IntervalValue { get; set; }
	private int? MinDocCountValue { get; set; }
	private double? MissingValue { get; set; }
	private double? OffsetValue { get; set; }
	private ICollection<KeyValuePair<Elastic.Clients.Elasticsearch.Serverless.Field, Elastic.Clients.Elasticsearch.Serverless.SortOrder>>? OrderValue { get; set; }
	private Elastic.Clients.Elasticsearch.Serverless.Script? ScriptValue { get; set; }
	private Elastic.Clients.Elasticsearch.Serverless.ScriptDescriptor ScriptDescriptor { get; set; }
	private Action<Elastic.Clients.Elasticsearch.Serverless.ScriptDescriptor> ScriptDescriptorAction { get; set; }

	/// <summary>
	/// <para>
	/// Enables extending the bounds of the histogram beyond the data itself.
	/// </para>
	/// </summary>
	public HistogramAggregationDescriptor<TDocument> ExtendedBounds(Elastic.Clients.Elasticsearch.Serverless.Aggregations.ExtendedBoundsFloat? extendedBounds)
	{
		ExtendedBoundsDescriptor = null;
		ExtendedBoundsDescriptorAction = null;
		ExtendedBoundsValue = extendedBounds;
		return Self;
	}

	public HistogramAggregationDescriptor<TDocument> ExtendedBounds(Elastic.Clients.Elasticsearch.Serverless.Aggregations.ExtendedBoundsFloatDescriptor descriptor)
	{
		ExtendedBoundsValue = null;
		ExtendedBoundsDescriptorAction = null;
		ExtendedBoundsDescriptor = descriptor;
		return Self;
	}

	public HistogramAggregationDescriptor<TDocument> ExtendedBounds(Action<Elastic.Clients.Elasticsearch.Serverless.Aggregations.ExtendedBoundsFloatDescriptor> configure)
	{
		ExtendedBoundsValue = null;
		ExtendedBoundsDescriptor = null;
		ExtendedBoundsDescriptorAction = configure;
		return Self;
	}

	/// <summary>
	/// <para>
	/// The name of the field to aggregate on.
	/// </para>
	/// </summary>
	public HistogramAggregationDescriptor<TDocument> Field(Elastic.Clients.Elasticsearch.Serverless.Field? field)
	{
		FieldValue = field;
		return Self;
	}

	/// <summary>
	/// <para>
	/// The name of the field to aggregate on.
	/// </para>
	/// </summary>
	public HistogramAggregationDescriptor<TDocument> Field<TValue>(Expression<Func<TDocument, TValue>> field)
	{
		FieldValue = field;
		return Self;
	}

	/// <summary>
	/// <para>
	/// The name of the field to aggregate on.
	/// </para>
	/// </summary>
	public HistogramAggregationDescriptor<TDocument> Field(Expression<Func<TDocument, object>> field)
	{
		FieldValue = field;
		return Self;
	}

	public HistogramAggregationDescriptor<TDocument> Format(string? format)
	{
		FormatValue = format;
		return Self;
	}

	/// <summary>
	/// <para>
	/// Limits the range of buckets in the histogram.
	/// It is particularly useful in the case of open data ranges that can result in a very large number of buckets.
	/// </para>
	/// </summary>
	public HistogramAggregationDescriptor<TDocument> HardBounds(Elastic.Clients.Elasticsearch.Serverless.Aggregations.ExtendedBoundsFloat? hardBounds)
	{
		HardBoundsDescriptor = null;
		HardBoundsDescriptorAction = null;
		HardBoundsValue = hardBounds;
		return Self;
	}

	public HistogramAggregationDescriptor<TDocument> HardBounds(Elastic.Clients.Elasticsearch.Serverless.Aggregations.ExtendedBoundsFloatDescriptor descriptor)
	{
		HardBoundsValue = null;
		HardBoundsDescriptorAction = null;
		HardBoundsDescriptor = descriptor;
		return Self;
	}

	public HistogramAggregationDescriptor<TDocument> HardBounds(Action<Elastic.Clients.Elasticsearch.Serverless.Aggregations.ExtendedBoundsFloatDescriptor> configure)
	{
		HardBoundsValue = null;
		HardBoundsDescriptor = null;
		HardBoundsDescriptorAction = configure;
		return Self;
	}

	/// <summary>
	/// <para>
	/// The interval for the buckets.
	/// Must be a positive decimal.
	/// </para>
	/// </summary>
	public HistogramAggregationDescriptor<TDocument> Interval(double? interval)
	{
		IntervalValue = interval;
		return Self;
	}

	/// <summary>
	/// <para>
	/// Only returns buckets that have <c>min_doc_count</c> number of documents.
	/// By default, the response will fill gaps in the histogram with empty buckets.
	/// </para>
	/// </summary>
	public HistogramAggregationDescriptor<TDocument> MinDocCount(int? minDocCount)
	{
		MinDocCountValue = minDocCount;
		return Self;
	}

	/// <summary>
	/// <para>
	/// The value to apply to documents that do not have a value.
	/// By default, documents without a value are ignored.
	/// </para>
	/// </summary>
	public HistogramAggregationDescriptor<TDocument> Missing(double? missing)
	{
		MissingValue = missing;
		return Self;
	}

	/// <summary>
	/// <para>
	/// By default, the bucket keys start with 0 and then continue in even spaced steps of <c>interval</c>.
	/// The bucket boundaries can be shifted by using the <c>offset</c> option.
	/// </para>
	/// </summary>
	public HistogramAggregationDescriptor<TDocument> Offset(double? offset)
	{
		OffsetValue = offset;
		return Self;
	}

	/// <summary>
	/// <para>
	/// The sort order of the returned buckets.
	/// By default, the returned buckets are sorted by their key ascending.
	/// </para>
	/// </summary>
	public HistogramAggregationDescriptor<TDocument> Order(ICollection<KeyValuePair<Elastic.Clients.Elasticsearch.Serverless.Field, Elastic.Clients.Elasticsearch.Serverless.SortOrder>>? order)
	{
		OrderValue = order;
		return Self;
	}

	public HistogramAggregationDescriptor<TDocument> Script(Elastic.Clients.Elasticsearch.Serverless.Script? script)
	{
		ScriptDescriptor = null;
		ScriptDescriptorAction = null;
		ScriptValue = script;
		return Self;
	}

	public HistogramAggregationDescriptor<TDocument> Script(Elastic.Clients.Elasticsearch.Serverless.ScriptDescriptor descriptor)
	{
		ScriptValue = null;
		ScriptDescriptorAction = null;
		ScriptDescriptor = descriptor;
		return Self;
	}

	public HistogramAggregationDescriptor<TDocument> Script(Action<Elastic.Clients.Elasticsearch.Serverless.ScriptDescriptor> configure)
	{
		ScriptValue = null;
		ScriptDescriptor = null;
		ScriptDescriptorAction = configure;
		return Self;
	}

	protected override void Serialize(Utf8JsonWriter writer, JsonSerializerOptions options, IElasticsearchClientSettings settings)
	{
		writer.WriteStartObject();
		if (ExtendedBoundsDescriptor is not null)
		{
			writer.WritePropertyName("extended_bounds");
			JsonSerializer.Serialize(writer, ExtendedBoundsDescriptor, options);
		}
		else if (ExtendedBoundsDescriptorAction is not null)
		{
			writer.WritePropertyName("extended_bounds");
			JsonSerializer.Serialize(writer, new Elastic.Clients.Elasticsearch.Serverless.Aggregations.ExtendedBoundsFloatDescriptor(ExtendedBoundsDescriptorAction), options);
		}
		else if (ExtendedBoundsValue is not null)
		{
			writer.WritePropertyName("extended_bounds");
			JsonSerializer.Serialize(writer, ExtendedBoundsValue, options);
		}

		if (FieldValue is not null)
		{
			writer.WritePropertyName("field");
			JsonSerializer.Serialize(writer, FieldValue, options);
		}

		if (!string.IsNullOrEmpty(FormatValue))
		{
			writer.WritePropertyName("format");
			writer.WriteStringValue(FormatValue);
		}

		if (HardBoundsDescriptor is not null)
		{
			writer.WritePropertyName("hard_bounds");
			JsonSerializer.Serialize(writer, HardBoundsDescriptor, options);
		}
		else if (HardBoundsDescriptorAction is not null)
		{
			writer.WritePropertyName("hard_bounds");
			JsonSerializer.Serialize(writer, new Elastic.Clients.Elasticsearch.Serverless.Aggregations.ExtendedBoundsFloatDescriptor(HardBoundsDescriptorAction), options);
		}
		else if (HardBoundsValue is not null)
		{
			writer.WritePropertyName("hard_bounds");
			JsonSerializer.Serialize(writer, HardBoundsValue, options);
		}

		if (IntervalValue.HasValue)
		{
			writer.WritePropertyName("interval");
			writer.WriteNumberValue(IntervalValue.Value);
		}

		if (MinDocCountValue.HasValue)
		{
			writer.WritePropertyName("min_doc_count");
			writer.WriteNumberValue(MinDocCountValue.Value);
		}

		if (MissingValue.HasValue)
		{
			writer.WritePropertyName("missing");
			writer.WriteNumberValue(MissingValue.Value);
		}

		if (OffsetValue.HasValue)
		{
			writer.WritePropertyName("offset");
			writer.WriteNumberValue(OffsetValue.Value);
		}

		if (OrderValue is not null)
		{
			writer.WritePropertyName("order");
			SingleOrManySerializationHelper.Serialize<KeyValuePair<Elastic.Clients.Elasticsearch.Serverless.Field, Elastic.Clients.Elasticsearch.Serverless.SortOrder>>(OrderValue, writer, options);
		}

		if (ScriptDescriptor is not null)
		{
			writer.WritePropertyName("script");
			JsonSerializer.Serialize(writer, ScriptDescriptor, options);
		}
		else if (ScriptDescriptorAction is not null)
		{
			writer.WritePropertyName("script");
			JsonSerializer.Serialize(writer, new Elastic.Clients.Elasticsearch.Serverless.ScriptDescriptor(ScriptDescriptorAction), options);
		}
		else if (ScriptValue is not null)
		{
			writer.WritePropertyName("script");
			JsonSerializer.Serialize(writer, ScriptValue, options);
		}

		writer.WriteEndObject();
	}
}

public sealed partial class HistogramAggregationDescriptor : SerializableDescriptor<HistogramAggregationDescriptor>
{
	internal HistogramAggregationDescriptor(Action<HistogramAggregationDescriptor> configure) => configure.Invoke(this);

	public HistogramAggregationDescriptor() : base()
	{
	}

	private Elastic.Clients.Elasticsearch.Serverless.Aggregations.ExtendedBoundsFloat? ExtendedBoundsValue { get; set; }
	private Elastic.Clients.Elasticsearch.Serverless.Aggregations.ExtendedBoundsFloatDescriptor ExtendedBoundsDescriptor { get; set; }
	private Action<Elastic.Clients.Elasticsearch.Serverless.Aggregations.ExtendedBoundsFloatDescriptor> ExtendedBoundsDescriptorAction { get; set; }
	private Elastic.Clients.Elasticsearch.Serverless.Field? FieldValue { get; set; }
	private string? FormatValue { get; set; }
	private Elastic.Clients.Elasticsearch.Serverless.Aggregations.ExtendedBoundsFloat? HardBoundsValue { get; set; }
	private Elastic.Clients.Elasticsearch.Serverless.Aggregations.ExtendedBoundsFloatDescriptor HardBoundsDescriptor { get; set; }
	private Action<Elastic.Clients.Elasticsearch.Serverless.Aggregations.ExtendedBoundsFloatDescriptor> HardBoundsDescriptorAction { get; set; }
	private double? IntervalValue { get; set; }
	private int? MinDocCountValue { get; set; }
	private double? MissingValue { get; set; }
	private double? OffsetValue { get; set; }
	private ICollection<KeyValuePair<Elastic.Clients.Elasticsearch.Serverless.Field, Elastic.Clients.Elasticsearch.Serverless.SortOrder>>? OrderValue { get; set; }
	private Elastic.Clients.Elasticsearch.Serverless.Script? ScriptValue { get; set; }
	private Elastic.Clients.Elasticsearch.Serverless.ScriptDescriptor ScriptDescriptor { get; set; }
	private Action<Elastic.Clients.Elasticsearch.Serverless.ScriptDescriptor> ScriptDescriptorAction { get; set; }

	/// <summary>
	/// <para>
	/// Enables extending the bounds of the histogram beyond the data itself.
	/// </para>
	/// </summary>
	public HistogramAggregationDescriptor ExtendedBounds(Elastic.Clients.Elasticsearch.Serverless.Aggregations.ExtendedBoundsFloat? extendedBounds)
	{
		ExtendedBoundsDescriptor = null;
		ExtendedBoundsDescriptorAction = null;
		ExtendedBoundsValue = extendedBounds;
		return Self;
	}

	public HistogramAggregationDescriptor ExtendedBounds(Elastic.Clients.Elasticsearch.Serverless.Aggregations.ExtendedBoundsFloatDescriptor descriptor)
	{
		ExtendedBoundsValue = null;
		ExtendedBoundsDescriptorAction = null;
		ExtendedBoundsDescriptor = descriptor;
		return Self;
	}

	public HistogramAggregationDescriptor ExtendedBounds(Action<Elastic.Clients.Elasticsearch.Serverless.Aggregations.ExtendedBoundsFloatDescriptor> configure)
	{
		ExtendedBoundsValue = null;
		ExtendedBoundsDescriptor = null;
		ExtendedBoundsDescriptorAction = configure;
		return Self;
	}

	/// <summary>
	/// <para>
	/// The name of the field to aggregate on.
	/// </para>
	/// </summary>
	public HistogramAggregationDescriptor Field(Elastic.Clients.Elasticsearch.Serverless.Field? field)
	{
		FieldValue = field;
		return Self;
	}

	/// <summary>
	/// <para>
	/// The name of the field to aggregate on.
	/// </para>
	/// </summary>
	public HistogramAggregationDescriptor Field<TDocument, TValue>(Expression<Func<TDocument, TValue>> field)
	{
		FieldValue = field;
		return Self;
	}

	/// <summary>
	/// <para>
	/// The name of the field to aggregate on.
	/// </para>
	/// </summary>
	public HistogramAggregationDescriptor Field<TDocument>(Expression<Func<TDocument, object>> field)
	{
		FieldValue = field;
		return Self;
	}

	public HistogramAggregationDescriptor Format(string? format)
	{
		FormatValue = format;
		return Self;
	}

	/// <summary>
	/// <para>
	/// Limits the range of buckets in the histogram.
	/// It is particularly useful in the case of open data ranges that can result in a very large number of buckets.
	/// </para>
	/// </summary>
	public HistogramAggregationDescriptor HardBounds(Elastic.Clients.Elasticsearch.Serverless.Aggregations.ExtendedBoundsFloat? hardBounds)
	{
		HardBoundsDescriptor = null;
		HardBoundsDescriptorAction = null;
		HardBoundsValue = hardBounds;
		return Self;
	}

	public HistogramAggregationDescriptor HardBounds(Elastic.Clients.Elasticsearch.Serverless.Aggregations.ExtendedBoundsFloatDescriptor descriptor)
	{
		HardBoundsValue = null;
		HardBoundsDescriptorAction = null;
		HardBoundsDescriptor = descriptor;
		return Self;
	}

	public HistogramAggregationDescriptor HardBounds(Action<Elastic.Clients.Elasticsearch.Serverless.Aggregations.ExtendedBoundsFloatDescriptor> configure)
	{
		HardBoundsValue = null;
		HardBoundsDescriptor = null;
		HardBoundsDescriptorAction = configure;
		return Self;
	}

	/// <summary>
	/// <para>
	/// The interval for the buckets.
	/// Must be a positive decimal.
	/// </para>
	/// </summary>
	public HistogramAggregationDescriptor Interval(double? interval)
	{
		IntervalValue = interval;
		return Self;
	}

	/// <summary>
	/// <para>
	/// Only returns buckets that have <c>min_doc_count</c> number of documents.
	/// By default, the response will fill gaps in the histogram with empty buckets.
	/// </para>
	/// </summary>
	public HistogramAggregationDescriptor MinDocCount(int? minDocCount)
	{
		MinDocCountValue = minDocCount;
		return Self;
	}

	/// <summary>
	/// <para>
	/// The value to apply to documents that do not have a value.
	/// By default, documents without a value are ignored.
	/// </para>
	/// </summary>
	public HistogramAggregationDescriptor Missing(double? missing)
	{
		MissingValue = missing;
		return Self;
	}

	/// <summary>
	/// <para>
	/// By default, the bucket keys start with 0 and then continue in even spaced steps of <c>interval</c>.
	/// The bucket boundaries can be shifted by using the <c>offset</c> option.
	/// </para>
	/// </summary>
	public HistogramAggregationDescriptor Offset(double? offset)
	{
		OffsetValue = offset;
		return Self;
	}

	/// <summary>
	/// <para>
	/// The sort order of the returned buckets.
	/// By default, the returned buckets are sorted by their key ascending.
	/// </para>
	/// </summary>
	public HistogramAggregationDescriptor Order(ICollection<KeyValuePair<Elastic.Clients.Elasticsearch.Serverless.Field, Elastic.Clients.Elasticsearch.Serverless.SortOrder>>? order)
	{
		OrderValue = order;
		return Self;
	}

	public HistogramAggregationDescriptor Script(Elastic.Clients.Elasticsearch.Serverless.Script? script)
	{
		ScriptDescriptor = null;
		ScriptDescriptorAction = null;
		ScriptValue = script;
		return Self;
	}

	public HistogramAggregationDescriptor Script(Elastic.Clients.Elasticsearch.Serverless.ScriptDescriptor descriptor)
	{
		ScriptValue = null;
		ScriptDescriptorAction = null;
		ScriptDescriptor = descriptor;
		return Self;
	}

	public HistogramAggregationDescriptor Script(Action<Elastic.Clients.Elasticsearch.Serverless.ScriptDescriptor> configure)
	{
		ScriptValue = null;
		ScriptDescriptor = null;
		ScriptDescriptorAction = configure;
		return Self;
	}

	protected override void Serialize(Utf8JsonWriter writer, JsonSerializerOptions options, IElasticsearchClientSettings settings)
	{
		writer.WriteStartObject();
		if (ExtendedBoundsDescriptor is not null)
		{
			writer.WritePropertyName("extended_bounds");
			JsonSerializer.Serialize(writer, ExtendedBoundsDescriptor, options);
		}
		else if (ExtendedBoundsDescriptorAction is not null)
		{
			writer.WritePropertyName("extended_bounds");
			JsonSerializer.Serialize(writer, new Elastic.Clients.Elasticsearch.Serverless.Aggregations.ExtendedBoundsFloatDescriptor(ExtendedBoundsDescriptorAction), options);
		}
		else if (ExtendedBoundsValue is not null)
		{
			writer.WritePropertyName("extended_bounds");
			JsonSerializer.Serialize(writer, ExtendedBoundsValue, options);
		}

		if (FieldValue is not null)
		{
			writer.WritePropertyName("field");
			JsonSerializer.Serialize(writer, FieldValue, options);
		}

		if (!string.IsNullOrEmpty(FormatValue))
		{
			writer.WritePropertyName("format");
			writer.WriteStringValue(FormatValue);
		}

		if (HardBoundsDescriptor is not null)
		{
			writer.WritePropertyName("hard_bounds");
			JsonSerializer.Serialize(writer, HardBoundsDescriptor, options);
		}
		else if (HardBoundsDescriptorAction is not null)
		{
			writer.WritePropertyName("hard_bounds");
			JsonSerializer.Serialize(writer, new Elastic.Clients.Elasticsearch.Serverless.Aggregations.ExtendedBoundsFloatDescriptor(HardBoundsDescriptorAction), options);
		}
		else if (HardBoundsValue is not null)
		{
			writer.WritePropertyName("hard_bounds");
			JsonSerializer.Serialize(writer, HardBoundsValue, options);
		}

		if (IntervalValue.HasValue)
		{
			writer.WritePropertyName("interval");
			writer.WriteNumberValue(IntervalValue.Value);
		}

		if (MinDocCountValue.HasValue)
		{
			writer.WritePropertyName("min_doc_count");
			writer.WriteNumberValue(MinDocCountValue.Value);
		}

		if (MissingValue.HasValue)
		{
			writer.WritePropertyName("missing");
			writer.WriteNumberValue(MissingValue.Value);
		}

		if (OffsetValue.HasValue)
		{
			writer.WritePropertyName("offset");
			writer.WriteNumberValue(OffsetValue.Value);
		}

		if (OrderValue is not null)
		{
			writer.WritePropertyName("order");
			SingleOrManySerializationHelper.Serialize<KeyValuePair<Elastic.Clients.Elasticsearch.Serverless.Field, Elastic.Clients.Elasticsearch.Serverless.SortOrder>>(OrderValue, writer, options);
		}

		if (ScriptDescriptor is not null)
		{
			writer.WritePropertyName("script");
			JsonSerializer.Serialize(writer, ScriptDescriptor, options);
		}
		else if (ScriptDescriptorAction is not null)
		{
			writer.WritePropertyName("script");
			JsonSerializer.Serialize(writer, new Elastic.Clients.Elasticsearch.Serverless.ScriptDescriptor(ScriptDescriptorAction), options);
		}
		else if (ScriptValue is not null)
		{
			writer.WritePropertyName("script");
			JsonSerializer.Serialize(writer, ScriptValue, options);
		}

		writer.WriteEndObject();
	}
}